using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;

namespace ConsoleApp1
{
    internal class Program
    {
        public interface Shape
        {
            double Count();
            bool Isvalue();
        }
        public class Rectangle : Shape
        {
            private double width;
            private double height;
            public Rectangle()
            {
                width = 0;
                height = 0;
            }
            public Rectangle(double width, double height)
            {
                this.width = width;
                this.height = height;
            }
            public Rectangle(double a)
            {
                width = a;
                height = 0;
            }
            public double Initwid
            {
                get { return width; }
                set { width = value; }
            }
            public double Initheight
            {
                get { return height; }
                set { height = value; }
            }
            public double Count()
            {
                if (!Isvalue())
                {
                    Console.WriteLine("矩形不合法！");
                    return 0;
                }
                else
                    return width * height;
            }
            public bool Isvalue()
            {
                return (width > 0 && height > 0);
            }
        }
        public class Square : Rectangle, Shape
        {
            private double len;
            public Square(double len)
            {
                this.len = len;
            }
            new double Initwid
            {
                get { return len; }
                set { len = value; }
            }
            new double Initheight
            {
                get { return len; }
                set { len = value; }
            }
            public double Count()
            {
                if (!Isvalue())
                    throw new Exception("正方形不合法！");
                return len * len;
            }
            public bool Isvalue()
            {
                return len > 0;
            }
        }
        public class Triangle : Shape
        {
            private double sidelen1;
            private double sidelen2;
            private double sidelen3;

            public Triangle(double sidelen1, double sidelen2, double sidelen3)
            {
                this.sidelen1 = sidelen1;
                this.sidelen2 = sidelen2;
                this.sidelen3 = sidelen3;
            }
            public double Sidelen1
            {
                get { return sidelen1; }
                set { sidelen1 = value; }
            }
            public double Sidelen2
            {
                get { return sidelen2; }
                set { sidelen2 = value; }
            }
            public double Sidelen3
            {
                get { return sidelen3; }
                set { sidelen3 = value; }
            }
            public double Count()
            {
                if (!Isvalue())
                    throw new Exception("三角形不合法！");
                double s = (sidelen1 + sidelen2 + sidelen3) / 2;
                return Math.Sqrt(s * (s - sidelen1) * (s - sidelen2) * (s - sidelen3));
            }
            public bool Isvalue()
            {
                if (sidelen1 <= 0 || sidelen2 <= 0 || sidelen3 <= 0)
                    return false;
                else
                    return sidelen1 + sidelen2 > sidelen3
                        && sidelen3 + sidelen1 > sidelen2
                        && sidelen2 + sidelen3 > sidelen1;
            }
        }
        public class Shapeprinter
        {
            public void Countshape(Shape shape)
            {
                shape.Count();
            }
        }
        public static void Main()
        {
            Rectangle r1 = new Rectangle(3, 2);
            double ans1 = r1.Count();
            Console.WriteLine(ans1);
            Triangle t1 = new Triangle(1, 4, 4);
            double ans2 = t1.Count();
            Console.WriteLine(ans2);
        }
    }
}
